<?php
/**
 * (actions) 提货汇总（prompt弹框输入,同步单个sku提货汇总）
 */
namespace App\Admin\Actions\Shipping;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
class SyncTotalSku extends AbstractTool
{
    /**
     * Render Export button.
     *
     * @return string
     */
    public function render()
    {
        $token = csrf_token();
        $script = <<<SCRIPT
$('.two-key-sync').unbind('click').click(function(e) {
    e.preventDefault();
    swal({
        input: "text",
        title: "同步单个sku",
        text : "请输入sku编码 (例：AM05102)",
        type : "info",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "确认&rarr;",
        showLoaderOnConfirm: true,
        cancelButtonText: "取消",
    }).then((result) => {
        if (result.value != undefined || result.value != null) {
            $.ajax({
                method: 'post',
                url: '/xqc/shipping/total-ajax',
                data: {
                    _token:"{$token}",
                    action:"totalSyncSku",
                    sku: result.value
                },
                success: function (data) {
                    if (typeof data === 'object') {
                        if (data.status) {
                            $.pjax.reload('#pjax-container');
                            toastr.success('操作成功 !');
                        } else {
                            swal(data.message, '', 'error');
                        }
                    }
                }
           });
        }
    });
});
SCRIPT;
        Admin::script($script);
        return <<<EOT
<div class="btn-group">
    <button class="btn btn-sm btn-default two-key-sync"><i class="fa fa-retweet"></i>&nbsp;同步单个sku</button>
</div>
EOT;
    }
}
